package com.ruoyi.app.controller;

import com.alibaba.fastjson.JSON;
import com.ruoyi.app.annotation.AppSecurity;
import com.ruoyi.app.util.ReqMsg;
import com.ruoyi.app.util.RspMsg;
import com.ruoyi.bizsys.domain.CustReplenishInfo;
import com.ruoyi.business.service.IRaiseLimitService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户端用户提额
 *
 * @author cyh
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/app/raiseLimit")
public class RaiseLimitController extends BaseController {

    private IRaiseLimitService raiseLimitService;

    @AppSecurity
    @PostMapping("/replenish")
    @Log(title = "信息补充接口", businessType = BusinessType.GET)
    public RspMsg replenishInfo(@Validated @RequestBody ReqMsg reqMsg) {
        CustReplenishInfo replenishInfo = JSON.parseObject(reqMsg.getData().toString(), CustReplenishInfo.class);
        checkAttribute(replenishInfo);
        raiseLimitService.contactCheck(replenishInfo);
        raiseLimitService.replenishInfoCheck();
        raiseLimitService.raiseLimitCheck(getCustNo());
        raiseLimitService.replenishInfo(replenishInfo);
        return RspMsg.RspMsgOk(true);
    }


    @AppSecurity
    @PostMapping("/check")
    @Log(title = "主动提额校验接口", businessType = BusinessType.GET)
    public RspMsg raiseLimitCheck(@Validated @RequestBody ReqMsg reqMsg) {
        if (reqMsg != null && "replenishInfo".equals(reqMsg.getData())) {
            raiseLimitService.replenishInfoCheck();
        }
        raiseLimitService.raiseLimitCheck(getCustNo());
        return RspMsg.RspMsgOk(true);
    }

}
